<?php namespace App\Core\Repository;

use App\Http\Controllers\Controller;

abstract class Listener {
    
    protected $name;
    protected $repository;
    protected $service;
    
    public function __construct(Controller $service) {
        $this->service = $service;
    }

    public function boot(Repository $repository){
        $this->repository = $repository;
    }

    public function fire($event){
        $eventMethod = 'on'.ucfirst($event);
        if(method_exists($this, $eventMethod)){
            $args = array_slice(func_get_args(), 1);
            call_user_func_array([$this, $eventMethod], $args);
        }
    }
    
    public function getName(){
        return $this->name ? $this->name : static::class;
    }
    
    public function setName($name){
        $this->name = $name;
    }
}
